home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / hotshot / log.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  5KB  |  194 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import _hotshot
  5. import os.path as os
  6. import parser
  7. import symbol
  8. import sys
  9. from _hotshot import WHAT_ENTER, WHAT_EXIT, WHAT_LINENO, WHAT_DEFINE_FILE, WHAT_DEFINE_FUNC, WHAT_ADD_INFO
  10. __all__ = [
  11.     'LogReader',
  12.     'ENTER',
  13.     'EXIT',
  14.     'LINE']
  15. ENTER = WHAT_ENTER
  16. EXIT = WHAT_EXIT
  17. LINE = WHAT_LINENO
  18.  
  19. class LogReader:
  20.     
  21.     def __init__(self, logfn):
  22.         self._filemap = { }
  23.         self._funcmap = { }
  24.         self._reader = _hotshot.logreader(logfn)
  25.         self._nextitem = self._reader.next
  26.         self._info = self._reader.info
  27.         if self._info.has_key('current-directory'):
  28.             self.cwd = self._info['current-directory']
  29.         else:
  30.             self.cwd = None
  31.         self._stack = []
  32.         self._append = self._stack.append
  33.         self._pop = self._stack.pop
  34.  
  35.     
  36.     def close(self):
  37.         self._reader.close()
  38.  
  39.     
  40.     def fileno(self):
  41.         """Return the file descriptor of the log reader's log file."""
  42.         return self._reader.fileno()
  43.  
  44.     
  45.     def addinfo(self, key, value):
  46.         '''This method is called for each additional ADD_INFO record.
  47.  
  48.         This can be overridden by applications that want to receive
  49.         these events.  The default implementation does not need to be
  50.         called by alternate implementations.
  51.  
  52.         The initial set of ADD_INFO records do not pass through this
  53.         mechanism; this is only needed to receive notification when
  54.         new values are added.  Subclasses can inspect self._info after
  55.         calling LogReader.__init__().
  56.         '''
  57.         pass
  58.  
  59.     
  60.     def get_filename(self, fileno):
  61.         
  62.         try:
  63.             return self._filemap[fileno]
  64.         except KeyError:
  65.             raise ValueError, 'unknown fileno'
  66.  
  67.  
  68.     
  69.     def get_filenames(self):
  70.         return self._filemap.values()
  71.  
  72.     
  73.     def get_fileno(self, filename):
  74.         filename = os.path.normcase(os.path.normpath(filename))
  75.         for fileno, name in self._filemap.items():
  76.             if name == filename:
  77.                 return fileno
  78.                 continue
  79.         
  80.         raise ValueError, 'unknown filename'
  81.  
  82.     
  83.     def get_funcname(self, fileno, lineno):
  84.         
  85.         try:
  86.             return self._funcmap[(fileno, lineno)]
  87.         except KeyError:
  88.             raise ValueError, 'unknown function location'
  89.  
  90.  
  91.     
  92.     def next(self, index = 0):
  93.         while None:
  94.             (what, tdelta, fileno, lineno) = self._nextitem()
  95.             if what == WHAT_ENTER:
  96.                 (filename, funcname) = self._decode_location(fileno, lineno)
  97.                 t = (filename, lineno, funcname)
  98.                 self._append(t)
  99.                 return (what, t, tdelta)
  100.             
  101.             if what == WHAT_EXIT:
  102.                 return (what, self._pop(), tdelta)
  103.             
  104.             if what == WHAT_LINENO:
  105.                 (filename, firstlineno, funcname) = self._stack[-1]
  106.                 return (what, (filename, lineno, funcname), tdelta)
  107.             
  108.             if what == WHAT_DEFINE_FILE:
  109.                 filename = os.path.normcase(os.path.normpath(tdelta))
  110.                 self._filemap[fileno] = filename
  111.                 continue
  112.             if what == WHAT_DEFINE_FUNC:
  113.                 filename = self._filemap[fileno]
  114.                 self._funcmap[(fileno, lineno)] = (filename, tdelta)
  115.                 continue
  116.             if what == WHAT_ADD_INFO:
  117.                 if tdelta == 'current-directory':
  118.                     self.cwd = lineno
  119.                 
  120.                 self.addinfo(tdelta, lineno)
  121.                 continue
  122.             raise ValueError, 'unknown event type'
  123.  
  124.     
  125.     def __iter__(self):
  126.         return self
  127.  
  128.     
  129.     def _decode_location(self, fileno, lineno):
  130.         
  131.         try:
  132.             return self._funcmap[(fileno, lineno)]
  133.         except KeyError:
  134.             if self._loadfile(fileno):
  135.                 filename = None
  136.                 funcname = None
  137.             
  138.             
  139.             try:
  140.                 (filename, funcname) = self._funcmap[(fileno, lineno)]
  141.             except KeyError:
  142.                 filename = self._filemap.get(fileno)
  143.                 funcname = None
  144.                 self._funcmap[(fileno, lineno)] = (filename, funcname)
  145.             except:
  146.                 None<EXCEPTION MATCH>KeyError
  147.             
  148.  
  149.             None<EXCEPTION MATCH>KeyError
  150.  
  151.         return (filename, funcname)
  152.  
  153.     
  154.     def _loadfile(self, fileno):
  155.         
  156.         try:
  157.             filename = self._filemap[fileno]
  158.         except KeyError:
  159.             print 'Could not identify fileId', fileno
  160.             return 1
  161.  
  162.         if filename is None:
  163.             return 1
  164.         
  165.         absname = os.path.normcase(os.path.join(self.cwd, filename))
  166.         
  167.         try:
  168.             fp = open(absname)
  169.         except IOError:
  170.             return None
  171.  
  172.         st = parser.suite(fp.read())
  173.         fp.close()
  174.         funcdef = symbol.funcdef
  175.         lambdef = symbol.lambdef
  176.         stack = [
  177.             st.totuple(1)]
  178.         while stack:
  179.             tree = stack.pop()
  180.             
  181.             try:
  182.                 sym = tree[0]
  183.             except (IndexError, TypeError):
  184.                 continue
  185.  
  186.             if sym == funcdef:
  187.                 self._funcmap[(fileno, tree[2][2])] = (filename, tree[2][1])
  188.             elif sym == lambdef:
  189.                 self._funcmap[(fileno, tree[1][2])] = (filename, '<lambda>')
  190.             
  191.             stack.extend(list(tree[1:]))
  192.  
  193.  
  194.